$(function() {
	admin.communitySysDict.init();
});
Namespace('admin.communitySysDict', {
	init : function() {
		easyui.util.initDatagrid('#datagrid', {
			onDblClickRow : function() {
			}
		});
	},
	query : function() {
		if (!$('#query-form').form('validate'))
			return;
		var data = $('#query-form').form('jsonObject');
		$('#datagrid').datagrid('load', data);
	},
	
	toAdd:function() {
		top.addTab("1",'添加', contextPath+'/community/sys/dict/toAdd');
	},
	
	add:function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        var url = contextPath + '/community/sys/dict/add';
		$.post(url, data, function (result) {
			$('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('创建成功');
				top.addTab("",'字典参数表', contextPath+'/community/sys/dict/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	toUpdate:function(id) {
		if (id != null) {
			top.addTab(id,'编辑', contextPath+'/community/sys/dict/toUpdate?id=' + id);
		}
	},
	
	update: function () {
	 	if(!$('#data-form').form('validate')) return;
        var data=$('#data-form').form('jsonObject');
        var url = contextPath + '/community/sys/dict/update';
        $('#datagrid').datagrid('loading');
		$.post(url, data, function (result) {
			 $('#datagrid').datagrid('loaded');
			if (result.code == 1) {
				top.showInfo('编辑成功');
				top.addTab("1",'字典参数表', contextPath+'/community/sys/dict/list');
			} else {
				top.showInfo(result.msg);
			}
		});
	},
	
	toDelete:function (id) {
		var tip = "确定要删除吗";
		$.messager.confirm('信息提示', tip, function (success) {
			if (!success) {
				return;
			}
            var url = contextPath + '/community/sys/dict/delete';
			$('#datagrid').datagrid('loading');
			$.post(url, {'id': id}, function (result) {
				$('#datagrid').datagrid('loaded');
				if (result.code == 1) {
					top.showInfo('操作成功');
					top.addTab("1",'字典参数表', contextPath+'/community/sys/dict/list');
				} else {
					top.showInfo(result.msg);
				}
			});

		});
	},
});